/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.sciRegister.controller;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.AllowSciPersonnelInfoDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.AuditSciPersonnelInfoDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoQueryCriteria;
import com.fzhucc.modules.sciRegister.domain.SciRegisterInfo;
import com.fzhucc.modules.sciRegister.domain.dto.*;
import com.fzhucc.modules.sciRegister.service.SciRegisterInfoService;
import com.fzhucc.modules.ts.domain.dto.TsTeamQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2024-04-26
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "登记表:管理")
@RequestMapping("/api/sciRegisterInfo")
public class SciRegisterInfoController {

    private final SciRegisterInfoService sciRegisterInfoService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciRegisterInfo:list')")
    public void exportSciRegisterInfo(HttpServletResponse response, SciRegisterInfoQueryCriteria criteria) throws IOException {
        sciRegisterInfoService.download(sciRegisterInfoService.queryAll(criteria), response);
    }

    @Log("我的导出数据")
    @ApiOperation("我的导出数据")
    @GetMapping(value = "/my/download")
    @PreAuthorize("@el.check('sciRegisterInfo:list')")
    public void myexportSciRegisterInfo(HttpServletResponse response, SciRegisterInfoQueryCriteria criteria) throws IOException {
        sciRegisterInfoService.download(sciRegisterInfoService.queryAllmy(criteria), response);
    }

    @GetMapping(value = "/my")
    @Log("查询我的登记表")
    @ApiOperation("查询我的登记表")
    public ResponseEntity<Object> my(SciRegisterInfoQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciRegisterInfoService.my(criteria,pageable), HttpStatus.OK);
    }

    @GetMapping
    @Log("查询登记表")
    @ApiOperation("查询登记表")
    @PreAuthorize("@el.check('sciRegisterInfo:list')")
    public ResponseEntity<Object> querySciRegisterInfo(SciRegisterInfoQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciRegisterInfoService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping(value = "/show")
    @Log("h5、小程序查询登记表")
    @ApiOperation("h5、小程序查询登记表")
    public ResponseEntity<Object> list(SciRegisterInfoQueryCriteria criteria, Pageable pageable){
        criteria.setIsShow(1);
        return new ResponseEntity<>(sciRegisterInfoService.queryAllh5(criteria,pageable), HttpStatus.OK);
    }

    @PutMapping(value = "/isAllowEdit")
    @Log("是否允许编辑")
    @ApiOperation("是否允许编辑")
    public ResponseEntity<Object> isAllowEdit(@Validated @RequestBody AllowSciRegisterInfoDto dto) {
        sciRegisterInfoService.isAllowEdit(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PostMapping
    @Log("新增登记表")
    @ApiOperation("新增登记表")
    @PreAuthorize("@el.check('sciRegisterInfo:add')")
    public ResponseEntity<Object> createSciRegisterInfo(@Validated @RequestBody SciRegisterInfoAddDto dto){
        return new ResponseEntity<>(sciRegisterInfoService.create(dto), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改登记表")
    @ApiOperation("修改登记表")
    @PreAuthorize("@el.check('sciRegisterInfo:edit')")
    public ResponseEntity<Object> updateSciRegisterInfo(@Validated @RequestBody SciRegisterInfoEditDto dto){
        sciRegisterInfoService.update(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除登记表")
    @ApiOperation("删除登记表")
    @PreAuthorize("@el.check('sciRegisterInfo:del')")
    public ResponseEntity<Object> deleteSciRegisterInfo(@RequestBody Integer[] ids) {
        sciRegisterInfoService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PutMapping(value = "/audit")
    @Log("登记表状态审核")
    @ApiOperation("登记表状态审核")
    public ResponseEntity<Object> auditSciRegisterInfo(@Validated @RequestBody AuditSciRegisterInfoDto dto){
        sciRegisterInfoService.auditSciRegisterInfo(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @GetMapping("/{id}")
    @Log("查询单个登记表")
    @ApiOperation("查询单个登记表")
    public SciRegisterInfoDto queryInfoById(@PathVariable Integer id) {
        return sciRegisterInfoService.findById(id);
    }

    @GetMapping(value = "/getIsXsJs")
    @Log("获取字典is_xs_js 线上平台建设情况")
    @ApiOperation("获取字典is_xs_js 线上平台建设情况")
    @AnonymousAccess
    public ResponseEntity<Object> getIsXsJs() {
        return new ResponseEntity<>(sciRegisterInfoService.getIsXsJs(),HttpStatus.OK);
    }

    @GetMapping(value = "/getJsModel")
    @Log("获取字典js_model 建设模式")
    @ApiOperation("获取字典js_model 建设模式")
    @AnonymousAccess
    public ResponseEntity<Object> getJsModel() {
        return new ResponseEntity<>(sciRegisterInfoService.getJsModel(),HttpStatus.OK);
    }

    @GetMapping(value = "/getZjSource")
    @Log("获取字典zj_source 资金来源")
    @ApiOperation("获取字典zj_source 资金来源")
    @AnonymousAccess
    public ResponseEntity<Object> getZjSource() {
        return new ResponseEntity<>(sciRegisterInfoService.getZjSource(),HttpStatus.OK);
    }
}